<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
			<el-form-item label="学生号" prop="studentId">
				<el-input v-model="queryParams.studentId" placeholder="请输入学生号" clearable size="small" @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="学生名称" prop="studentName">
				<el-input v-model="queryParams.studentName" placeholder="请输入学生名称" clearable size="small" @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="奖品号" prop="prizeId">
				<el-input v-model="queryParams.prizeId" placeholder="请输入奖品号" clearable size="small" @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="领取状态" prop="receiveType">
				<el-select v-model="queryParams.receiveType" placeholder="请选择领取状态" clearable size="small">
					<el-option v-for="dict in receiveTypeOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-table v-loading="loading" :data="prizewinrecordList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="Id" align="center" prop="id" />
			<el-table-column label="学生号" align="center" prop="studentId" />
			<el-table-column label="学生名称" align="center" prop="studentName" />
			<el-table-column label="考试号" align="center" prop="safetyExaminationId" />
			<el-table-column label="考试名称" align="center" prop="safetyExaminationName" />
			<el-table-column label="奖品号" align="center" prop="prizeId" />
			<el-table-column label="中奖时间" align="center" prop="prizeWinDate" />
			<el-table-column label="领取状态" align="center" prop="receiveType" />
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" type="text" icon="el-icon-edit" @click="confirmcollection(scope.row)" v-hasPermi="['system:prizewinrecord:edit']">确认领取</el-button>
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
		 @pagination="getList" />

	</div>
</template>

<script>
	import {
		listPrizewinrecord,
		getPrizewinrecord,
		updatePrizewinrecord
	} from "@/api/system/prizewinrecord";

	export default {
		name: "Prizewinrecord",
		components: {},
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 中奖信息表格数据
				prizewinrecordList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				//领取状态
				receiveTypeOptions: [],
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					studentId: null,
					studentName: null,
					safetyExaminationId: null,
					safetyExaminationName: null,
					prizeId: null,
					prizeWinDate: null,
					receiveType: null
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {
					studentId: [{
						required: true,
						message: "学生号不能为空",
						trigger: "blur"
					}],
					studentName: [{
						required: true,
						message: "学生名称不能为空",
						trigger: "blur"
					}],
					safetyExaminationId: [{
						required: true,
						message: "考试号不能为空",
						trigger: "blur"
					}],
					safetyExaminationName: [{
						required: true,
						message: "考试名称不能为空",
						trigger: "blur"
					}],
					prizeId: [{
						required: true,
						message: "奖品号不能为空",
						trigger: "blur"
					}],
					prizeWinDate: [{
						required: true,
						message: "中奖时间不能为空",
						trigger: "blur"
					}],
					receiveType: [{
						required: true,
						message: "领取状态不能为空",
						trigger: "change"
					}]
				}
			};
		},
		created() {
			this.getList();
			this.getDicts("prize_receive").then(response => {
				this.receiveTypeOptions = response.data;
			});
		},
		methods: {
			/** 查询中奖信息列表 */
			getList() {
				this.loading = true;
				if(this.$route.query.examinationId!=null){
					this.queryParams.safetyExaminationId = this.$route.query.examinationId;
				}
				listPrizewinrecord(this.queryParams).then(response => {
					this.prizewinrecordList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					id: null,
					studentId: null,
					studentName: null,
					safetyExaminationId: null,
					safetyExaminationName: null,
					prizeId: null,
					prizeWinDate: null,
					receiveType: null
				};
				this.resetForm("form");
			},
			// 重置queryParams
			requeryParams() {
				this.queryParams = {
					pageNum: 1,
					pageSize: 10,
					studentId: null,
					studentName: null,
					safetyExaminationId: null,
					safetyExaminationName: null,
					prizeId: null,
					prizeWinDate: null,
					receiveType: null
				};
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.id)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			/** 确认领取按钮操作 */
			confirmcollection(row) {
				const that = this;
				const ids = row.studentId || this.ids;
				if (row.receiveType == "已领取") {
					this.msgInfo("已领取，请勿重复领取！");
				} else {
					this.$confirm('是否确认领取学号为"' + ids + '"的奖品?', "提示", {
						confirmButtonText: "确定",
						cancelButtonText: "取消",
						type: "success"
					}).then(function() {
						that.queryParams.receiveType = "1";
						that.queryParams.id = row.id;
						return updatePrizewinrecord(that.queryParams);
					}).then(() => {
						this.requeryParams();
						this.getList();
						this.msgSuccess("领取成功！");
					})
				}
			}
		}
	};
</script>
